package com.atguigu.dao.impl;

import com.atguigu.dao.ContainerPortMapDao;
import com.atguigu.pojo.ContainerPortMap;

import java.util.List;


public class ContainerPortMapDaoImpl extends BaseDao implements ContainerPortMapDao {

    @Override
    public int addContainerPortMap(ContainerPortMap containerPortMap) {
        System.out.println("ContainerPortMapDaoImpl程序在[" + Thread.currentThread().getName() + "]线程中");
        String sql = "insert into t_containerPortMap(`id`,`containerId`,`out`,`in`) values(?,?,?,?);";
        return update(sql,containerPortMap.getId(), containerPortMap.getContainerId(),containerPortMap.getOut(),containerPortMap.getIn());
    }

    @Override
    public int deleteContainerPortMapById(String id) {
        String sql = "delete from t_containerPortMap where id=?";
        return update(sql, id);
    }
    @Override
    public int deleteContainerPortMapByContainerId(String containerId){
        String sql = "delete from t_containerPortMap where containerId=?";
        return update(sql, containerId);
    }
    @Override
    public int updateContainerPortMap(ContainerPortMap containerPortMap) {
        String sql = "update t_containerPortMap set `containerId`=?,`out`=?,`in`=? where id=?";
        return update(sql, containerPortMap.getContainerId(),containerPortMap.getOut(),containerPortMap.getIn(), containerPortMap.getId());
    }

    @Override
    public ContainerPortMap queryContainerPortMapById(String id) {
        String sql = "select `id`,`containerId`,`out`,`in` from t_containerPortMap where id=?";
        return queryForOne(ContainerPortMap.class, sql, id);
    }

    @Override
    public List<ContainerPortMap> queryContainerPortMaps() {// 查询全部
        String sql = "select `id`,`containerId`,`out`,`in` from t_containerPortMap";
        return queryForList(ContainerPortMap.class, sql);
    }

    @Override
    public List<ContainerPortMap> queryContainerPortMapByContainerId(String containerId){
        String sql = "select `id`,`containerId`,`out`,`in` from t_containerPortMap where containerId=?";
        return queryForList(ContainerPortMap.class, sql,containerId);
    }

    @Override
    public Integer queryForPageTotalCount() {//查询总条目数,为page分片做准备
        String sql = "select count(*) from t_containerPortMap";
        Number containerPortMapCount = (Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return containerPortMapCount.intValue();
    }
    @Override
    public ContainerPortMap queryContainerPortMapsByContainerIdAndOut(String containerId,String out) {
        String sql = "select `id`,`containerId`,`out`,`in` from t_containerPortMap where containerId=? and out=?";
        return queryForOne(ContainerPortMap.class, sql, containerId,out);
    }
    @Override
    public ContainerPortMap queryContainerPortMapsByContainerIdAndIn(String containerId,String in) {
        String sql = "select `id`,`containerId`,`out`,`in` from t_containerPortMap where containerId=? and in=?";
        return queryForOne(ContainerPortMap.class, sql, containerId,in);
    }

    @Override
    public List<ContainerPortMap> queryForPageItems(Integer begin, Integer pageSize) {
        String sql = "select `id`,`containerId`,`out`,`in` from t_containerPortMap limit ?,?";
        return queryForList(ContainerPortMap.class, sql, begin, pageSize);//查询数据片段
    }
}


